// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.1

package user

import (
	"audio-server/internal/model"
	"audio-server/internal/sqlutil"
	"context"

	"audio-server/internal/svc"
	"audio-server/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserInfoUpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserInfoUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserInfoUpdateLogic {
	return &UserInfoUpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserInfoUpdateLogic) UserInfoUpdate(req *types.UserInfoUpdateReq) (resp bool, err error) {
	id := sqlutil.GetUserId(l.ctx)
	avatar := req.Avatar
	nickname := req.Nickname
	gender := req.Gender
	usersModel := model.NewUsersModel(l.svcCtx.Conn)
	one, err := usersModel.FindOne(l.ctx, id)
	if err != nil {
		return false, err
	}
	one.Avatar = avatar
	one.Nickname = nickname
	one.Gender = int64(gender)
	err = usersModel.Update(l.ctx, one)
	if err != nil {
		return false, err
	}
	return true, nil
}
